<template>
	<view class="box" @click="toGoodsDetail">
		<!-- 商品图片开始 -->
		<view class="center">
			<image :src="item.images[0].url"></image>
			<!-- <u-lazy-load :image="item.commodityUrl"></u-lazy-load> -->
		</view>
		<!-- 商品图片结束 -->

		<!-- 商品信息开始 -->
		<view class="right">
			<view class="title">
				{{item.name}}
				<view class="tags">
					<text class="quota" v-if="item.maxGroupBuyNum">限购{{item.maxGroupBuyNum}}份</text>
					<text class="quota" v-if="item.personNum">{{item.personNum}}人成团</text>
					<text class="special">特价</text>
				</view>
			</view>
			<view class="bottom">
				<!-- salesType:1 零售  2团购  0 批发 -->
				<view class="price">
					<!-- 		¥<text>{{item.isGroupBuying=='0'?item.groupBuyPrice:item.salesPrice}}</text><text>库存{{item.inventory}}</text> -->
					
					¥<text>{{item.minPrice}}</text><text style="font-size: 20rpx;color: #7B7B7B;" v-if="item.stock">库存{{item.stock}}</text>
					<text v-if="item.groupPersonNum != null || item.groupPersonNum != undefined">已有{{item.groupPersonNum}}人拼团</text>
				</view>
				<view class="add-cart" @click="addCart" v-if="!item.isGroupbuy">
					<image src="../static/jiagou.png" mode=""></image>
				</view>
			</view>
		</view>
		<!-- 商品信息结束 -->

	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'
	import {
		addCartApi
	} from '../common/API/cartApi.js'
	export default {
		name: "goodItem",
		props: {
			type: String,
			item: {
				type: Object
			},
			personCount: {
				type: Number
			}
		},
		data() {
			return {};
		},
		computed: {
			...mapState('user', ['ylToken','ylEnterprise']),
			isShow() {
				const price = this.item.isGroupBuying == "1" ? this.item.salesPrice : this.item.groupBuyPrice
				return price
			},
		},
		onShow() {
			console.log(item,'item')
		},
		methods: {
			toGoodsDetail() {
				if(this.item.isGroupbuy) { // 团购
					uni.navigateTo({
						url: `/subPackages/goodsDetail/goodsDetail?code=${this.item.code}&activityCode=${this.item.activityCode}&isGroupbuy=true`
					})
				} else {
					console.log(this.item.enterpriseCode,'this.item')
					uni.navigateTo({
						url: `/subPackages/goodsDetail/goodsDetail?code=${this.item.code}`
					})
				}
				
			},
			async addCart() {
				// const res = await addCartApi({
				// 	commodityCode: this.item.commodityCode,
				// 	categoryName: this.item.categoryName,
				// 	number: 1,
				// 	picUrl: this.item.commodityUrls[0].url || '',
				// 	price: this.item.isGroupBuying == "1" ? this.item.salesPrice : this
				// 		.goodsDetail.groupBuyPrice,
				// 	uniqueId: this.item.uniqueId,
				// 	enterpriseCode: this.item.enterpriseCode,
				// 	isGroupBuying: this.item.isGroupBuying
				// })
				// if (res.status === 200) {
				// 	uni.$showMsg('添加到购物车')
				// }
			}
		}
	}
</script>

<style lang="scss">
	.box {
		display: flex;
		justify-content: space-between;
		align-items: center;
		height: 280rpx;
		margin-bottom: 16rpx;
		background-color: #fff;
		padding: 16rpx;
		border-radius: 16rpx;

		.left {
			flex: 1;
		}

		.center {
			flex: 3;
			margin-right: 16rpx;

			image {
				width: 260rpx;
				height: 248rpx;
				border-radius: 24rpx;
			}
		}

		.right {
			height: 100%;
			display: flex;
			flex: 7;
			flex-direction: column;
			justify-content: space-between;

			.title {
				color: #333;
				font-size: 34rpx;
				font-weight: 500;
			}

			.tags {
				font-size: 20rpx;
				margin-top: 10rpx;
				// margin-bottom: 82rpx;

				text {
					display: inline-block;
					font-size: 20rpx;
					margin-right: 20rpx;
					padding: 0 4rpx;
				}

				.quota {
					color: #59C9FF;
					background-color: #EEF9FF;
				}

				.special {
					color: #FA5151;
					background-color: #FFEDED;
				}
			}

			.bottom {
				display: flex;
				font-size: 24rpx;
				justify-content: space-between;
				align-items: center;

				.price {
					color: #FA5151;

					text {
						font-size: 36rpx;
						margin: 0 4rpx;

						&:last-child() {
							font-size: 20rpx;
							color: #7B7B7B;
						}
					}
				}

				.add-cart {
					width: 48rpx;
					height: 48rpx;

					image {
						width: 100%;
						height: 100%;
					}
				}
			}

			// .price {
			// 	display: flex;
			// 	justify-content: space-between;

			// 	.enterpriseName {
			// 		display: flex;
			// 		align-items: center;
			// 		color: #ccc;
			// 		font-size: 26rpx
			// 	}
			// }
		}
	}
</style>
